<template>
<div>
    <div class="padding border-bottom" >
        <el-button type="primary" @click="add">增加医生</el-button>
    </div>
    <div>
        <el-dialog  type="text" :title="opr == 'add'?'增加医生':'修改医生'"  :visible.sync="dialogFormVisible">
                <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"  >
                   
                 
                            
                    <div class="card-body">

                                <div class="input-group mb-3">   
                                     <el-form-item label-width="0px" prop="account" style="width: 70%">
                                        <el-input v-model="ruleForm.account"  
                                            placeholder="账号 6--12位"  ></el-input>
                                    </el-form-item> 
                                    <div class="input-group-append" style="width:30%;height:100%">                                       
                                            <div class="input-group-text">
                                            <span class="fas fa-user">account</span>
                                            </div>
                                        </div>                                
                                </div>

                                <div class="input-group mb-3">
                                     <el-form-item label-width="0px" prop="name" style="width: 70%">
                                     <el-input v-model="ruleForm.name"   placeholder="姓名 2--10位"></el-input> 
                                     </el-form-item> 
                                     <div class="input-group-append" style="width:30%;height:100%">     
                                        <div class="input-group-text">
                                        <span class="fas fa-user">name</span>
                                        </div>
                                    </div>
                                </div>

                                <div class="input-group mb-3">
                                    <el-form-item label-width="0px" prop="id_card" style="width: 70%">
                                        <el-input v-model="ruleForm.id_card"  maxlength="18" 
                                           show-word-limit placeholder="身份证18位"></el-input> 
                                    </el-form-item> 
                                    <div class="input-group-append" style="width:30%;height:100%">  
                                        <div class="input-group-text">
                                        <span class="fas fa-envelope">身份证号</span>
                                        </div>
                                    </div>
                                </div>
                                
                                <div class="input-group mb-3" v-show="show">
                                    <el-form-item label-width="0px" prop="password" style="width: 70%">
                                         <el-input type="password" v-model="ruleForm.password" autocomplete="off"  
                                        placeholder="请输入密码6--12位"></el-input>
                                    </el-form-item> 
                                    <div class="input-group-append" style="width: 30%;height:100%" >
                                        <div class="input-group-text">
                                        <span class="fas fa-lock">密码</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="input-group mb-3" v-show="show">
                                    <el-form-item label-width="0px" prop="checkPass" style="width: 70%">
                                        <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off" 
                                       placeholder="请再次输入密码"></el-input>
                                    </el-form-item> 
                                    <div class="input-group-append" style="width: 30%;height:100%">
                                        <div class="input-group-text">
                                        <span class="fas fa-lock">确认密码</span>
                                        </div>
                                    </div>
                                </div>

                                <el-form-item label-width="0px" prop="birthDate" >
                                <div class="input-group mb-3" >
                                        <el-date-picker
                                            v-model="ruleForm.birthDate"
                                            type="date" 
                                            value-format="yyyy-MM-dd" 
                                            placeholder="请选择出生年月" style="width: 70%">
                                        </el-date-picker>
                                    <div class="input-group-append" style="width: 30%;height:100%">
                                        <div class="input-group-text">
                                        <span class="fas fa-user">生日</span>
                                        </div>
                                    </div>
                                </div>
                                 </el-form-item>

                                <div class="input-group mb-3">
                                    <select id="inputStatus" class="form-control custom-select" style="width: 70%" v-model="ruleForm.sex" >
                                    <option   value="男">男</option>
                                    <option value="女">女</option>
                                    </select>
                                        <div class="input-group-append" style="width: 30%;height:100%">
                                            <div class="input-group-text">
                                            <span class="fas fa-user">性别</span>
                                            </div>
                                        </div>
                                </div>
                                
                               
                                <div class="input-group mb-3" > 
                                    <el-form-item label-width="0px" prop="telephone" style="width: 70%">
                                        <el-input  v-model.number="ruleForm.telephone" maxlength="11" 
                                           show-word-limit autocomplete="off"></el-input> 
                                    </el-form-item> 
                                    <div class="input-group-append" style="width:30%;height:100%"> 
                                        <div class="input-group-text">
                                        <span class="fas fa-user">电话号码</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="input-group mb-3" >
                                    <span style="width: 15%" v-show="!show">当前头像：</span>
                                    <img :src="doc==''?'':'http://192.168.6.189:8080/'+doc.photo" alt="无图片" title="无图片" style="width: 20%" v-show="!show"/>
                                    <input id="file"  type="file"  @change="file($event)" multiple="multiplt" accept=".npg,.jpg" style="width: 35%"/>
                                    
                                    <div class="input-group-append" style="width: 30%;height:100%">
                                        <div class="input-group-text">
                                        <span class="fas fa-user">头像</span>
                                        </div>
                                    </div>
                                </div>
                                
                                <el-form-item label-width="0px" prop="entry_time" >
                                <div class="input-group mb-3" >
                                   
                                         <el-date-picker
                                            v-model="ruleForm.entry_time"
                                            type="date" 
                                            value-format="yyyy-MM-dd" 
                                            placeholder="请选择入职时间" style="width: 70%">
                                        </el-date-picker>
                                    
                                    <div class="input-group-append"  style="width: 30%;height:100%">
                                        <div class="input-group-text">
                                        <span class="fas fa-user">入职时间</span>
                                        </div>
                                    </div>
                                </div>
                                </el-form-item> 

                               <div class="input-group mb-3">
                                    <select  class="form-control custom-select"  v-model="ruleForm.dep_id" >
                                         <!--  循环加入科室 -->
                                     <option  disabled value="0">请选择</option>
                                    <option v-for="dep in departments" :key="dep.id" :value="dep.id">{{dep.name}}</option>
                                    </select>
                                        <div class="input-group-append">
                                            <div class="input-group-text">
                                            <span class="fas fa-user">科室</span>
                                            </div>
                                        </div>
                                </div> 
                                <div class="input-group mb-3">
                                    <select  class="form-control custom-select" v-model="ruleForm.title_id">                       
                                    <!-- 循环加入职称 -->
                                    <option  disabled value="0">请选择</option>
                                    <option v-for="title in titles" :key="title.id" :value="title.id">{{title.name}}</option>
                                    </select>
                                        <div class="input-group-append">
                                            <div class="input-group-text">
                                            <span class="fas fa-user">职称</span>
                                            </div>
                                        </div>
                                </div>
                            <div class="input-group mb-3">
                                <select  class="form-control custom-select" v-model="ruleForm.status">
                                <option   value="1">门诊/住院</option>                               
                                <option value="2">药房</option>
                                <option value="3">检查室</option>
                                </select>
                                <div class="input-group-append">
                                        <div class="input-group-text">
                                        <span class="fas fa-user">状态</span>
                                        </div>
                                </div>
                            </div>
                            <div class="form-group">
                                  <label for="inputDescription">介绍Description</label>
                                <el-form-item label-width="0px" prop="description" >
                                      
                                        <el-input
                                            type="textarea"
                                            placeholder="字数1到100"
                                            v-model="ruleForm.description"
                                            maxlength="100"
                                            show-word-limit
                                            rows="4"
                                            >
                                            </el-input>  
                                </el-form-item>   
                            </div>
                            </div>
                            <div class="row">
                                <div class="col-12">
                                    <el-button @click="cancel" class="btn btn-secondary">Cancel</el-button>
                                    <el-button @click="resetForm()" class="btn btn-secondary" v-show="show">重置</el-button>
                                    <el-button type="primary" @click="submitForm('ruleForm')" class="btn btn-success float-right">Create new Doctor</el-button>

                                </div>
                            </div>

                </el-form> 
        </el-dialog>
    </div>

    <!-- 医生详情表格 -->
    <div>
        <el-dialog  type="text" title='医生详情'  :visible.sync="vieWdialogFormVisible">
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>医生详情</span>
                <el-button style="float: right; padding: 3px 0" type="text" @click="cancel">关闭</el-button>
            </div>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    姓名
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.name}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    账号
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.account}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    手机号码
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.phoneNumber}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    身份证号
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.idCard}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    编号
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.no}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    出生日期
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.birthDate}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    性别
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.sex}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    科室
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.depName}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    职称
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.titleName}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12" >
                <el-col :span="8">
                    <el-card shadow="always">
                    入职时间
                    </el-card>
                </el-col>
                <el-col :span="8" >
                    <el-card shadow="hover" >
                    {{doctorView.entryTime}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    头像
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    
                        <img :src="doctorView==''?'':'http://localhost:8080/'+doctorView.photo" width="80px" height="80px"/>
                    </el-card>
                    
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    介绍
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.description}}
                    </el-card>
                </el-col>
            </el-row>
            <el-row :gutter="12">
                <el-col :span="8">
                    <el-card shadow="always">
                    状态
                    </el-card>
                </el-col>
                <el-col :span="8">
                    <el-card shadow="hover">
                    {{doctorView.state=='1'?"门诊住院":doctorView.state=='2'?"药房":"检查"}}
                    </el-card>
                </el-col>
            </el-row>
        </el-card>
        </el-dialog>
    </div>
<el-divider><i class="el-icon-mobile-phone"></i></el-divider>
<el-divider content-position="right">乌拉！</el-divider>
    <div style="text-align:center">

        <div class="doctor_seacher">
            姓名:<el-input v-model="search_name" placeholder="请输入姓名" class="doctor_seacher_info"></el-input>
            职称: <el-select v-model="value" placeholder="请选择" class="doctor_seacher_info">
                        <el-option  :value="0">所有</el-option>
                        <el-option v-for="title in titles" :key="title.id" :label="title.name" :value="title.id"></el-option>
                </el-select>
        起:<el-date-picker v-model="date1" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
            止:<el-date-picker v-model="date2" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
            <el-button type="primary" @click="searche" icon="el-icon-search" style="margin-left:20px">搜索</el-button>
               <el-divider><i class="el-icon-mobile-phone"></i></el-divider>
        </div>
 
        <section class="content">
           
           <!-- <el-divider content-position="right"></el-divider> -->
            <div class="card-body p-0" >
            <table class="table table-striped projects">
                <thead>
                    <tr>
                        <th style="width: 10%">
                            序号
                        </th>
                        <th style="width: 10%">
                            医生名字
                        </th>
                        <th style="width: 10%">
                            年龄
                        </th>
                        <th style="width: 10%">
                            性别
                        </th>
                        <th style="width: 10%">
                            科室
                        </th>
                        <th style="width: 10%">
                            职称
                        </th>
                        <th style="width: 10%">
                            状态
                        </th>
                        <th style="width: 25%" class="text-center">
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(doctor,index) in doctorsPage" :key="doctor.id">
                        <td> {{index+1}} </td>
                        <td>{{doctor.name}}</td>
                        <td>{{doctor.birthDate}}</td>
                        <td>{{doctor.sex}}</td>
                        <td>{{doctor.depName}}</td>
                        <td>{{doctor.titleName}}</td>
                        <td>{{doctor.state=='1'?'就诊':doctor.state=='2'?'药房':doctor.state=='2'?'检查':'离职'}}</td>
                        
                        <td class="project-actions text-center">
                            <a class="btn btn-primary btn-sm"  @click="viewDoctor(doctor.id)">
                                <i class="fas fa-folder">
                                </i>
                                查看详情
                            </a>
                            <a class="btn btn-info btn-sm" @click="update(doctor.id)">
                                <i class="fas fa-pencil-alt">
                                </i>
                                修改
                            </a>
                            <a class="btn btn-danger btn-sm" @click="del(doctor.id)">
                                <i class="fas fa-trash">
                                </i>
                                删除
                            </a>
                        </td>
                    </tr>
                </tbody>
            </table>
            </div>
        
        </section>
        <el-pagination background layout="sizes,prev, pager, next"
        :page-sizes="[1, 2, 3, 4]"
        @size-change="sizeChange"
        @current-change="currentChange"
        :total="totalPage" :page-size="pageSize"
        ></el-pagination>

    
    </div>   
</div>
</template>
<script>
    const axios = require("axios");
    export default {
    data(){

        //校验密码
         var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        }else if(value.length>12 || value.length<6){
            callback(new Error('密码长度在6--12位'));
        
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return{
        ruleForm: {
            account: '',
            name:'',
            password: '',
            checkPass:'',
            photo:'',//头像
            entry_time:'',//入职时间
            birthDate:'',//出生年月日
            telephone:'',//手机
            description:'',//介绍
            title_id:'0',//职称id
            dep_id:'0',//科室id
            sex:'男',//默认男
            id_card:'',//身份证
            status:'1'//默认在职
            
        },
        //校验弹出框表单
        rules: {
            account: [
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    { min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur' }
                    ],
            name: [
                    { required: true, message: '请输入姓名', trigger: 'blur' },
                    { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
                    ],
          password: [
                        { validator: validatePass, trigger: 'blur' }
                    ],
          checkPass: [
                    { validator: validatePass2, trigger: 'blur' }
                    ],
            
            entry_time:[
                    { required: true, message: '请选择入职时间', trigger: 'blur' },
                    ],//入职时间
            birthDate:[
                    { required: true, message: '请选择出生年月日', trigger: 'blur' },
                    ],//出生年月日
            telephone:[
                    { required: true, message: '请输入电话号码', trigger: 'blur' },
                    {  pattern:/^\d{11,11}$/, message: '长度在 11 个数字', trigger: 'blur' },
                      { type: 'number', message: '必须为数字值'},
                     
                    ],//手机
            description:[
                    { required: true, message: '请输入简介', trigger: 'blur' },
                    { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
                    ],//介绍
            id_card:[{ required: true, message: '请输入身份证号', trigger: 'blur' },
                    { min: 18, max: 18, message: '长度在 18  个字符', trigger: 'blur' }
                    ],//身份证
        },
          
          dialogFormVisible:false,//控制弹框的显示
          date1: '',
          date2: '',
          format: 'yyyy-MM-dd',
          search_name: '',
          search_title: '',
          doctors:[],
          doctorsPage:[],
          titles: [],//职称
          departments: [],//科室
          value:'',
          totalPage: 10,
          pageSize: 2,
          opr:'add',//控制增加与修改
          vieWdialogFormVisible: false,//控制显示医生详细信息表格
          show:false,//控制密码文本框显示
          id:'0',
          doc:'',
          doctorView: ''//医生详细信息
      }  
    },
    methods:{
      searche(){
        axios.post("http://192.168.6.189:8080/hpl-doctor/getByCondition",{
            name:this.search_name,
            titleId:this.value,
            startTime:this.date1,
            endTime:this.date2
        }).then((r) => {
          if (r.data.code === 200) {
           this.doctors = r.data.data;
           this.goPage(1,this.pageSize);
           this.totalPage=this.doctors.length;
          }else if(r.data.code === 403){
                                this.$notify({
                                    title: '警告',
                                    message: '没有查询医生的权限',
                                    type: 'warning'
                                    }); 
                            }else if(r.data.code === 500){
                                this.$notify({
                                    title: '警告',
                                    message: r.data.msg,
                                    type: 'warning'
                                    }); 
                            }else{
                                this.$notify({
                                    title: '警告',
                                    message: '系统繁忙！',
                                    type: 'warning'
                                    }); 
                            }
        });
      },
      viewDoctor(id){
          axios.get("http://192.168.6.189:8080/hpl-doctor/getById?id="+id).then((r) => {
                if(r.data.code == 200){
                    this.doctorView=r.data.data;
                    this.vieWdialogFormVisible=true;//显示弹框
                }else if(r.data.code === 403){
                                this.$notify({
                                    title: '警告',
                                    message: '没有查询医生的权限',
                                    type: 'warning'
                                    }); 
                            }else if(r.data.code === 500){
                                this.$notify({
                                    title: '警告',
                                    message: r.data.msg,
                                    type: 'warning'
                                    }); 
                            }else{
                                this.$notify({
                                    title: '警告',
                                    message: '系统繁忙！',
                                    type: 'warning'
                                    }); 
                            }
            })
      },
      sizeChange(r){
        this.doctorsPage.splice(0,this.doctorsPage.length);
        this.pageSize=r;
        this.goPage(1,r);
      },
      currentChange(r){
        this.goPage(r,this.pageSize)
      },
      goPage(nowPage,pageSize){
        this.doctorsPage.splice(0,this.doctorsPage.length);
         let start = (parseInt(nowPage)-1)*parseInt(pageSize);
         for (let i = 0; i < parseInt(pageSize); i++) {
             if(i+start<this.doctors.length){
                 this.doctorsPage[i]=this.doctors[start+i];
             }
         }
      },
      //打开增加管理员弹框
      add(){
            this.opr='add';
            this.show=true;
            this.resetForm();
            this.doctorView='';
            this.dialogFormVisible = true; 
          },
      update(id){
            
             this.resetForm();
             this.doctorView='';
             this.show=false;
           axios.get("http://192.168.6.189:8080/hpl-doctor/getById?id="+id).then((r) => {
                if(r.data.code == 200){
                    this.opr='update';
                    this.id=id;
                    this.doc =r.data.data;

                    this.ruleForm.account=this.doc.account;
                    this.ruleForm.name=this.doc.name;
                    
                    this.ruleForm.password=this.doc.password;
                    this.ruleForm.checkPass=this.doc.password;
                    this.ruleForm.photo=this.doc.photo;
                    this.ruleForm.birthDate=this.doc.birthDate;
                    this.ruleForm.description=this.doc.description;
                    this.ruleForm.sex=this.doc.sex;
                    this.ruleForm.telephone=parseInt(this.doc.phoneNumber);
                    this.ruleForm.entry_time=this.doc.entryTime;
                    this.ruleForm.title_id=this.doc.titleId;
                    this.ruleForm.dep_id=this.doc.depId;
                    this.ruleForm.id_card=this.doc.idCard;
                    this.ruleForm.status=this.doc.state;
                    this.dialogFormVisible = true;//显示弹框
                }else if(r.data.code === 403){
                                this.$notify({
                                    title: '警告',
                                    message: '没有查询医生的权限',
                                    type: 'warning'
                                    }); 
                            }else if(r.data.code === 500){
                                this.$notify({
                                    title: '警告',
                                    message: r.data.msg,
                                    type: 'warning'
                                    }); 
                            }else{
                                this.$notify({
                                    title: '警告',
                                    message: '系统繁忙！',
                                    type: 'warning'
                                    }); 
                            }
             })
            },
        del(id){
            if(confirm("你确定要删除吗？")){
                axios.get("http://192.168.6.189:8080/hpl-doctor/del?id="+id).then((r) => {
                    if(r.data.code===200){
                                    this.$message({
                                        message: '恭喜你，这是一条成功消息',
                                        type: 'success'
                                    });	
                                    this.cancel();
                                    this.doclist();
                                }else if(r.data.code === 403){
                                this.$notify({
                                    title: '警告',
                                    message:r.data.msg ,
                                    type: 'warning'
                                    }); 
                            }else if(r.data.code === 500){
                                this.$notify({
                                    title: '警告',
                                    message: r.data.msg,
                                    type: 'warning'
                                    }); 
                            }else{
                                this.$notify({
                                    title: '警告',
                                    message: '系统繁忙！',
                                    type: 'warning'
                                    }); 
                            }
                })
            }
            
        },
          //获取头像文件
        file:function (event){
						var files = event.target.files;
						this.ruleForm.photo=files[0];
					},
        //增加提交到后台
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                  if (valid) { 
                    if(this.ruleForm.photo==''){ 
                        this.$notify({
                            title: '警告',
                            message: '上传头像失败，请选择头像',
                            type: 'warning'
                            });  
                            return;          
                        }
                        if(this.ruleForm.photo.size>1048576){ 
                        this.$notify({
                            title: '警告',
                            message: '上传头像失败，文件太大了',
                            type: 'warning'
                            });  
                            return;           
                        }
                        
                    
                    if(this.ruleForm.dep_id==='0'){ 
                        this.$notify({
                            title: '警告',
                            message: '没有选择科室',
                            type: 'warning'
                            });  
                            return;           
                        }
                    if(this.ruleForm.title_id==='0'){ 
                        this.$notify({
                            title: '警告',
                            message: '没有选择职称',
                            type: 'warning'
                            });  
                            return;           
                        }
                   
                   

						var formData = new FormData();
						formData.append('account', this.ruleForm.account);
						formData.append('name', this.ruleForm.name);
						formData.append('password', this.ruleForm.password);
						formData.append('file', this.ruleForm.photo);//上传的文件
						formData.append('entryTime', this.ruleForm.entry_time);
                        formData.append('birthDate', this.ruleForm.birthDate);
						formData.append('phoneNumber', this.ruleForm.telephone);
						formData.append('description',this.ruleForm.description);
                        formData.append('titleId', this.ruleForm.title_id);
                        formData.append('depId', this.ruleForm.dep_id);
						formData.append('sex', this.ruleForm.sex);
						formData.append('idCard',this.ruleForm.id_card);
                        formData.append('state',this.ruleForm.status);
                        if(this.id!='0'&&this.opr=='update'){
                            formData.append("id",this.id);
                        }
						let config = {
							headers: {
								'Content-Type' : 'multipart/form-data',
							}
						}
						axios.post("http://192.168.6.189:8080/hpl-doctor/"+this.opr,
                        formData,config).then(r=>{
                            if(r.data.code===200){
                                 this.$message({
                                    message: '恭喜你，这是一条成功消息',
                                    type: 'success'
                                });	
                                this.cancel();
                                this.doclist();
                            }else{
                                this.$notify({
                                    title: '警告',
                                    message:r.data.msg ,
                                    type: 'warning'
                                    });           
                                
                            }
                             
                        });


                } else {
                    this.$notify({
                                    title: '警告',
                                    message:'数据不规范，请检查',
                                    type: 'warning'
                                    });  
                    return false;
                }
            });
        },
        changefile(){//清除选中的文件
                //重写一遍input元素
                if(document.getElementById('file')!=null){
                    document.getElementById("file").addEventListener("change",this.handleInput);
                    document.getElementById("file").value=''
                }
               
             },
        resetForm() {
            this.changefile(),//调用方法清除选中的文件
            this.ruleForm.photo='';          
            this.ruleForm.title_id='0';
            this.ruleForm.dep_id='0';
            this.ruleForm.sex='男';
            this.ruleForm.status='1';
            this.ruleForm.account= '';
            this.ruleForm.name= '';
            this.ruleForm.password= '';
            this.ruleForm.checkPass= '';
            this.ruleForm.photo= '';
            this.ruleForm.entry_time= '';
            this.ruleForm.birthDate= '';
            this.ruleForm.telephone= '';
            this.ruleForm.description= '';
            this.ruleForm.id_card= ''; 
        },
         cancel(){
             //重置表单
            this.resetForm();
            this.dialogFormVisible = false;
            this.doctorView='';
            this.vieWdialogFormVisible=false;
         },
         doclist(){
              //查询医生
            axios.get("http://192.168.6.189:8080/hpl-doctor/getAll").then((r) => {
                if(r.data.code == 200){
                     this.doctors = r.data.data;
                     this.goPage(1,this.pageSize);
                     this.totalPage=this.doctors.length;

                }else if(r.data.code === 403){
                                        this.$notify({
                                            title: '警告',
                                            message: r.data.msg,
                                            type: 'warning'
                                            }); 
                                    }else if(r.data.code === 500){
                                        this.$notify({
                                            title: '警告',
                                            message: r.data.msg,
                                            type: 'warning'
                                            }); 
                                    }else{
                                this.$notify({
                                    title: '警告',
                                    message: '系统繁忙！',
                                    type: 'warning'
                                    }); 
                            } 
            })
            //查询职称
            axios.get("http://192.168.6.189:8080/hpl-title/getAll").then((r) => {
                if(r.data.code == 200){
                     this.titles = r.data.data;
                }else if(r.data.code === 403){
                                        this.$notify({
                                            title: '警告',
                                            message: r.data.msg,
                                            type: 'warning'
                                            }); 
                                    }else if(r.data.code === 500){
                                        this.$notify({
                                            title: '警告',
                                            message: r.data.msg,
                                            type: 'warning'
                                            }); 
                                    }else{
                                this.$notify({
                                    title: '警告',
                                    message: '系统繁忙！',
                                    type: 'warning'
                                    }); 
                            } 
            })
            //查询科室
            axios.get("http://192.168.6.189:8080/hpl-department/htGetAll").then((r) => {
                if(r.data.code == 200){
                     this.departments = r.data.data;
                }else if(r.data.code === 403){
                                        this.$notify({
                                            title: '警告',
                                            message: r.data.msg,
                                            type: 'warning'
                                            }); 
                                    }else if(r.data.code === 500){
                                        this.$notify({
                                            title: '警告',
                                            message: r.data.msg,
                                            type: 'warning'
                                            });
                                            top.location.href="/login" 
                                    }else{
                                this.$notify({
                                    title: '警告',
                                    message: '系统繁忙！',
                                    type: 'warning'
                                    }); 
                            } 
            })
         },
        
       
    }, 
    mounted(){
        this.doclist(); 
         }
}
</script>
<style scoped>
 .doctor_seacher{
     width: max-content;
     float: left;
     margin-bottom: 10px;
 }
 .doctor_seacher_info{
     width: 120px;
     margin-right: 10px;
 }
</style>
